home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / lin.fit < prev    next >
Text File  |  1995-03-23  |  2KB  |  79 lines

  1. Article 2975 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!samsung!usc!ucsd!ucbvax!agate!shelby!msi.umn.edu!noc.MR.NET!gacvx2.gac.edu!hhdist
  3. From: NELSON%VWSCYG@vmsc.oac.uci.edu (Matthew A. Nelson)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: linear fits with errors
  6. Message-ID: <EC03481D60001CB7@gacvx2.gac.edu>
  7. Date: 18 Dec 90 17:27:00 GMT
  8. Lines: 62
  9. To: handhelds@gac.edu
  10. Return-path: <NELSON%VWSCYG@vmsc.oac.uci.edu>
  11. To: handhelds@gac.edu
  12. X-VMS-To: HANDHELDS
  13.  
  14.  
  15.   Below you will find a routine for doing fits to the line Y=a+bX, and
  16. a routine to predict a value of y0 given an x0.  I realize that these are
  17. already built into the 48, but the routines below not only provide the
  18. coefficients a, b, and the predicted y0, but also the standard deviations
  19. in these values, Sa, Sb and Sy0.  Knowing these errors is often times
  20. crucial, and I have long been amazed that linear regression routines
  21. usually omit them.             
  22.   The formulae used for the calculations below were gotten from
  23. "Introduction to the Theory of Error", by Yardley Beers (Addison-
  24. Wesley, 1962).
  25.  
  26.   The first routine takes your sigma-dat, and calculates a, Sa, b, Sb
  27. and an estimate of the errors in the y-data, Sy (this is used in the
  28. second routine).  It changes the display mode and displays the relevant
  29. information, and also creates the global variables a, Sa, b, Sb and Sy.
  30.  
  31. %%HP: T(3)A(R)F(.);
  32. \<< RCLF \-> f
  33.   \<< 4 FIX \GSY SQ
  34. \GSX^2 * \GSX*Y \GSX \GSY *
  35. * 2 * - N\GS \GSX*Y SQ
  36. * + N\GS \GSX^2 * \GSX SQ
  37. - / \GSY^2 SWAP - N\GS
  38. 2 - / \v/ DUP 'Sy'
  39. STO \-> sy
  40.     \<< CLLCD N\GS N\GS
  41. \GSX^2 * \GSX SQ - / \v/
  42. sy * DUP 'Sb' STO
  43. \->STR "Sb: " SWAP +
  44. 6 DISP N\GS \GSX*Y * \GSX
  45. \GSY * - N\GS \GSX^2 * \GSX
  46. SQ - / DUP 'b' STO
  47. \->STR " b: " SWAP +
  48. 5 DISP \GSX^2 N\GS \GSX^2
  49. * \GSX SQ - / \v/ sy *
  50. DUP 'Sa' STO \->STR
  51. "Sa: " SWAP + 4
  52. DISP \GSX^2 \GSY * \GSX
  53. \GSX*Y * - N\GS \GSX^2 *
  54. \GSX SQ - / DUP 'a'
  55. STO \->STR " a: "
  56. SWAP + 3 DISP
  57. "fit to: Y=a+bX" 1
  58. DISP 7 FREEZE
  59.     \>> f STOF
  60.   \>>
  61. \>>
  62.  
  63.   The second routine takes x0 from the stack and returns the predicted
  64. y0 in level 2, and it's error, Sy0, in level 1.  The first routine must
  65. be executed before this one, in order to calculate the required coefficients.
  66.  
  67. %%HP: T(3)A(R)F(.);
  68. \<< \-> x
  69.   \<< x b * a + \GSX^2
  70. \GSX 2 * x * - N\GS x
  71. SQ * + N\GS \GSX^2 * \GSX
  72. SQ - / \v/ Sy *
  73.   \>>
  74. \>>
  75.  
  76.   Any comments may be thrown to Matt Nelson (nelson@psroot.ps.uci.edu)
  77.  
  78.  
  79.